package com.kexilo;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * Kexilo权限管理系统启动类
 * 
 * @author Kexilo
 */
@SpringBootApplication(scanBasePackages = {
    "com.kexilo.common",
    "com.kexilo.auth", 
    "com.kexilo.system"
})
@EnableCaching
@EnableAsync
@EnableScheduling
@EnableTransactionManagement
public class KexiloApplication {

    public static void main(String[] args) {
        // 设置系统属性
        System.setProperty("spring.application.name", "kexilo-admin");
        System.setProperty("server.servlet.context-path", "/api");
        
        // 启用优雅停机
        System.setProperty("server.shutdown", "graceful");
        System.setProperty("spring.lifecycle.timeout-per-shutdown-phase", "30s");
        
        // JVM参数优化提示
        printJvmOptimizationTips();
        
        // 启动应用
        SpringApplication application = new SpringApplication(KexiloApplication.class);
        
        // 配置启动Banner
        application.setBanner(new KexiloBanner());
        
        // 添加启动监听器
        application.addListeners(new KexiloApplicationListener());
        
        application.run(args);
        
        System.out.println("\n" +
            "  __ _  _____ _  _(_) |  ___  \n" +
            " / / / / ____ \\| |/ / | |/ _ \\ \n" +
            "/ / / /  ____> < / /| | | (_) |\n" +
            "\\ \\_\\ \\ |____|\\_|_/ |_|_|\\___/ \n" +
            " \\___/_/                       \n" +
            "\n" +
            "Kexilo权限管理系统启动成功！\n" +
            "API文档地址：http://localhost:8080/api/swagger-ui.html\n" +
            "管理界面：http://localhost:8080\n");
    }
    
    /**
     * 打印JVM优化建议
     */
    private static void printJvmOptimizationTips() {
        System.out.println("========================================");
        System.out.println("JVM优化建议：");
        System.out.println("-Xms1024m -Xmx2048m");
        System.out.println("-XX:+UseG1GC");
        System.out.println("-XX:MaxGCPauseMillis=200");
        System.out.println("-XX:+UseStringDeduplication");
        System.out.println("========================================");
    }
}